<template>
	<view class="contain">
		<view class="btn" v-for="(item,index) in list" :key="item.id" @click="handleQuestion(item)">
			<text>{{item.name}}</text>
			<view class="contentBox">
				<text>{{item.content}}</text>
				<image src="/static/image/meright.webp" mode=""></image>
			</view>
		</view>
		<u-popup mode="center" :show="show" @close="close" @open="open" round="20">
			<view class="pupopForm">
				<view class="popupNavBox">
					<image src="/static/image/homeImage/kefubianji.png" mode=""></image>
					<text>联系客服</text>
				</view>
				<view class="popupInput">
					<view class="popupTextArea">
						<textarea @blur="bindTextAreaBlur" placeholder="请您详细的描述一下您的问题,客服HH将及时跟进解决哦~"/>
					</view>
					<view class="popupUpLoad">
						<u-upload height="100" width="100" uploadIcon="plus" :fileList="fileList1"
							@afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="4"></u-upload>
					</view>
				</view>
				<view class="popupBtn" @click="submitForm">
					提交
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				list: [{
						id: 1,
						name: "退出登录",
						content: "退出需要重新登录"
					},
					{
						id: 2,
						name: "清除缓存",
						content: "100GB"
					},
					{
						id: 3,
						name: "应用版本号",
						content: "100"
					},
					{
						id: 4,
						name: "应用版本名称",
						content: "1.0.0"
					},
					{
						id: 5,
						name: "问题反馈",
						content: "~点击弹框外部任意位置可关闭弹窗~"
					}
				],
				fileList1: [],
			};
		},
		methods: {
			submitForm(){
				uni.showToast({
					icon: "none",
					title: "已提交"
				})
				this.show=false
			},
			bindTextAreaBlur: function(e) {
				console.log(e.detail.value)
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			handleQuestion(item) {
				switch (item.id) {
					case 1:
						uni.showModal({
							title: '温馨提示',
							content: '您确定要退出登录吗？',
							success: function(res) {
								if (res.confirm) {
									uni.removeStorageSync("TOKEN")
									uni.reLaunch({
										url: '/pages/login/login'
									});
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});

						break;
					case 2:
						uni.showToast({
							icon: "none",
							title: "已清理缓存"
						})
						break;
					case 5:
						this.show = true
						break;
					default:
						break;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.contain {
		overflow: hidden;
		background-color: red;

		.btn {
			height: 100rpx;
			background-color: #fff;
			border-bottom: .5rpx solid #ccc;
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			justify-content: space-between;

			.contentBox {
				display: flex;
				align-items: center;

				text {
					color: #9f9f9f;
					font-size: 30rpx;
				}

				image {
					width: 10rpx;
					height: 10rpx;
					margin-left: 20rpx;
				}
			}

		}
	}

	.pupopForm {
		height: 600rpx;
		background-color: #fff;
		width: 600rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		align-items: center;

		.popupNavBox {
			height: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-bottom: 25rpx;

			image {
				width: 30rpx;
				height: 30rpx;
				margin-right: 20rpx;
			}
		}

		.popupInput {
			width: 500rpx;
			height: 280rpx;
			background-color: #f0f0f0;
			border-radius: 10rpx;
			margin-bottom: 25rpx;
			
			.popupTextArea{
				height: 150rpx;
				padding: 10rpx 20rpx;
				box-sizing: border-box;
				textarea{
					width: 100%;
					height: 100%;
					font-size: 20rpx;
				}
			}
			.popupUpLoad{
				height: 150rpx;
				padding:20rpx 0rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: center;
			}
		}

		.popupBtn {
			height: 100rpx;
			width: 500rpx;
			background-color: #f0f0f0;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 10rpx;
		}
	}
</style>